package FlexCup;

import HashMap.GenerarCodigoNASM;
import HashMap.Nodo.Operaciones.Funciones.AlmacenFunciones;
import HashMap.Pila;

public class PDL {

    public static void main(String[] args) {
        if (args.length != 2) {
            System.out.println("El comando correcto es: java -jar PracticaPDL.jar entrada.txt salida.txt");
        } else {
            try {
                new parser(new PracticaPDL(new java.io.FileInputStream(args[0]))).parse();
                StringBuilder builder = new StringBuilder();
                builder.append(Pila.getInstancia().generarCodigoNASMInicioPila());
                builder.append("segment .text\nglobal main\n");
                builder.append(AlmacenFunciones.getInstancia().generarCodigoNASM());
                builder.append("main:\n");
                builder.append(GenerarCodigoNASM.getInstancia().generarCodigo());
                builder.append("ret");
                LecturaEscrituraFichero.writeFile(args[1], builder.toString());
            } catch (java.io.FileNotFoundException e) {
                System.out.println("Archivo \"" + args[0] + "\" no encontrado");
            } catch (java.io.IOException e) {
                System.out.println("IO error scanning file \"" + args[0] + "\"");
                System.out.println(e);
            } catch (Exception e) {
                System.out.println("Unexpected exception:");
                e.printStackTrace();
            }
        }
    }
}
